<!--
	学生端
-->
<template>
<div class="student-home-box">
	<el-table :data="homeworkList" style="width: 100%">
		<el-table-column prop="title" label="标题" />
		<el-table-column prop="content" label="内容" />
		<el-table-column property="startTime" label="开始时间" >
			<template #default="scope">
				{{getDateString(scope.row.startTime)}}
			</template>
		</el-table-column>
		<el-table-column property="endTime" label="结束时间" >
			<template #default="scope">
				{{getDateString(scope.row.endTime)}}
			</template>
		</el-table-column>
		<el-table-column label="附件" >
			<template #default="scope">
				<div v-if="scope.row.appendix" title="点击下载" class="appendix-box"
					 @click="download(scope.row.appendix)">
					<el-icon :size="20"><files /></el-icon>
					{{scope.row.appendix?scope.row.appendix.split('/')[4]:''}}
				</div>
			</template>
		</el-table-column>
		<el-table-column label="发布教师" >
			<template #default="scope">
				{{
					studentInfoData.thisEditCourse.teacherList.filter(item=>{
						if(item.id==scope.row.teacherId){
							return true;
						}
						return false;})[0].name
				}}
			</template>
		</el-table-column>
		<el-table-column label="操作" width="145px">
			<template #default="scope">
				<el-button size="mini" type="primary"
						   @click="pathToHomeworkEdit(scope.row)">详情</el-button>

			</template>
		</el-table-column>
	</el-table>
</div>
</template>

<script>
import axios from "@/plugins/axios";
import ipconfig from "@/utils/ipconfig";
import {ElMessage} from "element-plus";
import DateUtils from "@/utils/DateUtils";

export default {
	name: "StudentHomework",
	data(){
		return {
			/**
			 * 学员登录数据
			 */
			studentInfoData:this.$store.state.studentInfoData,
			/**
			 * 任务数据
			 */
			homeworkList:[],
		}
	},
	methods:{
		/*
		* 获取显示时间
		* @param date 时间戳
		* @returns {string}
		* */
		getDateString(date){
			return DateUtils.getDateSting(date);
		},
		download(path){
			window.open("http://localhost:8080/file/download?path="+path);
		},
		/**
		 * 跳转到课程任务详情
		 * @param homeworkItem
		 */
		pathToHomeworkEdit(homeworkItem){
			this.studentInfoData.editHomework=homeworkItem;
			this.$router.push({path:'/student/courseInfo/homeworkEdit'});
		}
	},
	mounted() {
		// 获取课程的任务列表
		axios.get(ipconfig.address+"/homework/homeworkList/"
			+this.studentInfoData.thisEditCourse.id).then((response)=>{
			if(response.data.code==200){
				this.homeworkList=response.data.data;
				console.log(this.homeworkList)
				ElMessage.success(response.data.message);
			}else{
			    ElMessage.warning(response.data.message);
			}
		}).catch((error)=>{
		    console.log(error);
		});
	}
}
</script>

<style lang="scss" scoped>
.appendix-box{
	cursor: pointer;
	&:hover{
		color: red;
	}
}
.student-home-box{
	width: 100%;

}
</style>